package com.fr.report.io.xml;

import com.fr.base.Style;
import com.fr.report.Elem;
import java.util.ArrayList;
import java.util.Hashtable;
import java.util.List;

public class SynchronizedStyleList
{
  private static Hashtable threadStyleHash = new Hashtable();
  private List styleList = new ArrayList();
  private List[] index_cellLists = new List[0];

  public static SynchronizedStyleList getSynchronizedStyleList(Thread paramThread)
  {
    SynchronizedStyleList localSynchronizedStyleList = (SynchronizedStyleList)threadStyleHash.get(paramThread);
    if (localSynchronizedStyleList == null)
    {
      localSynchronizedStyleList = new SynchronizedStyleList();
      threadStyleHash.put(paramThread, localSynchronizedStyleList);
    }
    return localSynchronizedStyleList;
  }

  public static SynchronizedStyleList removeSynchronizedCellStyleList(Thread paramThread)
  {
    return ((SynchronizedStyleList)threadStyleHash.remove(paramThread));
  }

  public synchronized void put(int paramInt, Elem paramElem)
  {
    if (this.index_cellLists.length <= paramInt)
    {
      int i = this.index_cellLists.length * 3 / 2 + 1;
      if (i <= paramInt)
        i = paramInt + 1;
      List[] arrayOfList = this.index_cellLists;
      this.index_cellLists = new List[i];
      System.arraycopy(arrayOfList, 0, this.index_cellLists, 0, arrayOfList.length);
      this.index_cellLists[paramInt] = new ArrayList();
    }
    if (this.index_cellLists[paramInt] == null)
      this.index_cellLists[paramInt] = new ArrayList();
    List localList = this.index_cellLists[paramInt];
    localList.add(paramElem);
  }

  public static synchronized void flush_current_thread_styles()
  {
    SynchronizedStyleList localSynchronizedStyleList = getSynchronizedStyleList(Thread.currentThread());
    List[] arrayOfList = localSynchronizedStyleList.index_cellLists;
    for (int i = 0; i < arrayOfList.length; ++i)
    {
      int j;
      List localList = arrayOfList[i];
      if (localList != null)
        for (j = 0; j < localList.size(); ++j)
          ((Elem)localList.get(j)).setStyle(localSynchronizedStyleList.getStyle(i));
    }
  }

  public synchronized void clear()
  {
    this.styleList.clear();
    this.index_cellLists = null;
  }

  public synchronized int getStyleCount()
  {
    return this.styleList.size();
  }

  public synchronized Style getStyle(int paramInt)
  {
    if ((paramInt < 0) || (paramInt >= this.styleList.size()))
      return Style.DEFAULT_STYLE;
    return ((Style)this.styleList.get(paramInt));
  }

  public synchronized int indexOfStyle(Style paramStyle)
  {
    int i = this.styleList.indexOf(paramStyle);
    if (i == -1)
    {
      this.styleList.add(paramStyle);
      return (this.styleList.size() - 1);
    }
    return i;
  }

  public synchronized void addStyle(Style paramStyle)
  {
    this.styleList.add(paramStyle);
  }
}